package view.backend.graveyard;

import java.awt.Font;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import view.generaldesign.DesignLayout;

/**
 *
 * @author Sonny Sandberg
 */
public class AdminGraveYardName 
{
    private JPanel adminGraveYardPanel;
    private JTextField tFieldName;
    private AdminGraveYard adminGraveYard;

    public AdminGraveYardName(AdminGraveYard view)
    {
        adminGraveYard = view;
        
        adminGraveYardPanel = new JPanel(null);
        adminGraveYardPanel.setBounds(0, 0, 300, 85);
        adminGraveYardPanel.setBorder(BorderFactory.createTitledBorder(DesignLayout.T_FIELD_RED, "Kirkegård", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, DesignLayout.STANDARD));
        adminGraveYardPanel.setOpaque(false);
        
        JLabel lblName = new JLabel("Navn");
        lblName.setBounds(10, 25, 150, 18);
        lblName.setFont(DesignLayout.STANDARD.deriveFont(Font.BOLD));
        
        tFieldName = new JTextField();
        tFieldName.setBounds(10, 45, 250, 25);
        tFieldName.setBorder(DesignLayout.T_FIELD_RED);
        tFieldName.setBackground(DesignLayout.T_FIELD_BG_COLOR);
        tFieldName.setFont(DesignLayout.STANDARD);
        tFieldName.addKeyListener(new KeyAdapter() 
        {
            @Override
            public void keyReleased(KeyEvent e)
            {
                adminGraveYard.getGraveYardObject().setName(tFieldName.getText());
                adminGraveYard.updateOverviewPanel();
                adminGraveYard.doLookUp();
            }
        });
        
        adminGraveYardPanel.add(lblName);
        adminGraveYardPanel.add(tFieldName);
        
        adminGraveYardPanel.setVisible(true);
    }
    
    public void setFieldsFromModel()
    {        
        tFieldName.setText(adminGraveYard.getGraveYardObject().getName());
    }

    public JPanel getPanel()
    {
        return adminGraveYardPanel;
    }
}